package com.quotes.charts;

import java.awt.Color;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.*;
import com.quotes.datamodell.*;
import com.quotes.datamodell.TimeSeries;
import com.quotes.dates.*;
import com.quotes.indicators.*;

public class CoppockChart extends LineChart
{
	private static final long serialVersionUID = 1L;
	private CoppockIndicator indicator = null;
	
	public CoppockChart(Quotes quotes, TimeRange range, int a, int b, int c) {
		super(quotes, range);
		indicator = new CoppockIndicator(quotes, a, b, c);
		
		this.createChart(quotes);
		logger.debug("CoppockChart created!");
	}
	
	protected XYDataset createXyDataset(Quotes product) {
		TimeSeriesCollection data = new TimeSeriesCollection();

		TimeSeries coppoc = indicator.getCoppoc().extract(range);
    	data.addSeries(coppoc.convertToChartTimeSeries("Coppock"));
    	
		return data;
	}
	
	@Override
	protected XYPlot manipulatePlot(XYPlot plot) {
		XYItemRenderer renderer = plot.getRenderer();
		renderer.setSeriesPaint(0, Color.black);
		
		addVerticalMarker(plot, 0, Color.black);
		TimeSeries coppoc = indicator.getCoppoc().extract(range);
		
		for (TimeRange range : coppoc.getPositiveRanges()) {
			addHorizontalMarker(plot, range, org.jfree.chart.ChartColor.LIGHT_GREEN);
		}

		for (TimeRange range : coppoc.getNegativeRanges()) {
			addHorizontalMarker(plot, range, org.jfree.chart.ChartColor.LIGHT_RED);
		}
		
		return plot;
	}
}
